package com.example.a2306_shop

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.a2306_shop.databinding.ActivityWelBinding
import com.example.lib_base.mvvm.BaseViewActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 广告页  5秒倒计时结束后 判断是否登录  如果未登录跳转到登录界面  如果已登录  跳转到主页
 */
class WelActivity : BaseViewActivity<ActivityWelBinding>() {
    override fun initData() {

    }

    override fun initView() {
        lifecycleScope.launch {
            for (i in 5 downTo 1){
                binding.djs.text = "${i}秒|跳过"
                delay(1000)
            }
            //登录拦截  在所有跳转界面 判断是否登录了 以及是否需要登录  如果需要登录但没有登录  跳转到登录界面   其他情况跳转到相应界面
           /* if(SPUtils.getInstance().getString("token").isNotEmpty()){
                ARouter.getInstance().build("/app/MainActivity").navigation()
            }else{
                ARouter.getInstance().build("/user/LoginActivity").navigation()
            }*/
            //验证登录拦截器是否起作用
            ARouter.getInstance().build("/app/MainActivity").navigation(this@WelActivity,object:NavigationCallback{
                override fun onFound(postcard: Postcard?) {
                }

                override fun onLost(postcard: Postcard?) {
                }

                override fun onArrival(postcard: Postcard?) {
                    //当页面跳转成功后 接收当前页面
                    finish()
                }

                override fun onInterrupt(postcard: Postcard?) {
                }
            })

        }
    }

    override fun getLayout(): Int  = R.layout.activity_wel

}